package exploration;

import java.awt.BorderLayout;
import java.awt.Container;

import javax.swing.JFrame;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.AbstractTableModel;

public class APlainTable {
	public static void main(String[] args) {
		JFrame tableFrame = new JFrame("Table Space");
		tableFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		Container tableFrameContentPane = tableFrame.getContentPane();
		tableFrameContentPane.add(new ChartsTables(), BorderLayout.CENTER);
		tableFrame.pack();
		tableFrame.setVisible(true);
	}
}

class ChartsTables extends JTable{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public ChartsTables() {
		super(new ChartsTableModel());
		setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
		/* testing the listener */
		this.getModel().addTableModelListener(new TableModelListener() {

			@Override
			public void tableChanged(TableModelEvent arg0) {
				System.out.println("TableChanged called");
			}
			
		});
	}
	

}

class ChartsTableModel extends AbstractTableModel {
    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	int data[][] = new int[10][10];
	
	public ChartsTableModel(){
		super();
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				data[i][j] = i * j;
			}
		}
	}

	public String getColumnName(int col) {
        return ((Integer) col).toString();
    }
    
    public int getRowCount() { 
    	return 10; 
    }
    
    public int getColumnCount() { 
    	return 10; 
    }
    
    public Object getValueAt(int row, int col) {
        return data[row][col];
    }
    
    public boolean isCellEditable(int row, int col) { 
    	return true; 
    }
    
    public void setValueAt(Object value, int row, int col) {
    	System.out.println("Set Value called");
    	data[row][col] = Integer.valueOf((String) value);
        //fireTableCellUpdated(row, col);
    }
}
